package processor;

import org.apache.http.HttpHost;
import selenium.WeiBoMSelenium;
import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.processor.PageProcessor;
import utils.CodeUtil;

/**
 * Created by zhangcheng on 17/4/18.
 */
public class WeiboMPageProcessor implements PageProcessor {

    private Site site = Site.me()
            .setDomain("http://weibo.com/")
            .setUserAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.75 Safari/537.36")
            .setRetryTimes(3)
            .setHttpProxy(new HttpHost("10.101.1.6", 80))
            .setSleepTime(1000)
            .addHeader("Accept-Language", "zh-CN,zh;q=0.8")
            .addHeader("Accept", "application/json, text/plain, */*")
            .addHeader("Content-Type", "application/x-www-form-urlencoded")
            .addHeader("Cookie", "_T_WM=b9a79c6fcb51ba378119718fbf644bf2; SCF=AkWMTXlt24R4Huksml1QkFfmkTnE4Ag0ZxMY1z4BcsvFPodf_kB-kN-0TUyFYaK-dYu810N-uyQ3c8I07URb0pM.; SUBP=0033WrSXqPxfM725Ws9jqgMF55529P9D9WWsYlU1OflQ6r8kw5BMGwxR5JpX5o2p5NHD95QfSKq0eoB4Soq0Ws4DqcjMi--NiK.Xi-2Ri--ciKnRi-zNSoMNSKn7SKMRS7tt; WEIBOCN_WM=20005_0002; SUB=_2A250BExvDeRhGeNL7VET9CfKzT-IHXVXB1QnrDV6PUJbkdANLWnbkW118lnCJPmK0LXm3nzXAM6xYsMbAA..; SUHB=0RyaPqqZIbI08o; SSOLoginState=1493187647; H5_INDEX=0_all; H5_INDEX_TITLE=%E7%94%A8%E6%88%B76775805787; M_WEIBOCN_PARAMS=oid%3D4100788432771042%26sourceType%3Dweixin%26featurecode%3D20000180%26lfid%3D102803_ctg1_8999_-_ctg1_8999_home%26luicode%3D20000174%26uicode%3D20000061%26fid%3D4100788432771042")
            .addHeader("Host", "m.weibo.cn")
            .addHeader("Proxy-Authorization", "Basic NzYxNzg3Onp6bDY2MTAyOF4=")
            .addHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.75 Safari/537.36")
            .addHeader("Proxy-Connection", "keep-alive")
            .addHeader("Referer", "http://weibo.com/ttarticle/p/show?id=2309404098740582488478")
            .addHeader("X-Requested-With", "XMLHttpRequest");

    public void process(Page page) {
        System.out.println("pageinfo:");
        System.out.println(page.getRawText());
    }

    public WeiboMPageProcessor() throws Exception {
        //this.site = WeiBoMSelenium.click(this.site, "18007303287", "qwertsekfo1");
    }

    public Site getSite() {
        return site;
    }

    public static void main(String[] args) throws Exception {
        Spider.create(new WeiboMPageProcessor()).addUrl("http://m.weibo.cn/api/container/getIndex?type=all&queryVal=tfboy&containerid=100103type%3D1%26q%3Dtfboy&page=1").run();
    }
}
